package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"studygin-2/controller"
	"studygin-2/middleware"
	"studygin-2/model"
)

func init() {
	model.ConnectDB()
}

func main() {
	engine := gin.Default()
	routerGroup := engine.Group("/api")
	{
		routerGroup.POST("/register", controller.Register)
		routerGroup.POST("/login", controller.Login)
	}
	protectd := engine.Group("/api/admin")
	{
		protectd.Use(middleware.JwtAuthMiddleware())
		protectd.POST("/user", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{
				"status":  "success",
				"message": "authorized"})
		})
		protectd.POST("curUser", controller.CurrentUser)
	}
	err := engine.Run(":9999")
	if err != nil {
		return
	}
}
